home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / doom / quake_ad.zip / HIPQW.ZIP / SRC / HIPCOUNT.QC < prev    next >
Text File  |  1997-01-16  |  4KB  |  193 lines

  1. /* Counter QuickC program
  2.    By Jim Dose'  9/13/96
  3.    Copyright (c)1996 Hipnotic Interactive, Inc.
  4.    All rights reserved.
  5.    Do not distribute.
  6. */
  7.  
  8. float COUNTER_TOGGLE = 1;
  9. float COUNTER_LOOP = 2;
  10. float COUNTER_STEP = 4;
  11. float COUNTER_RESET = 8;
  12. float COUNTER_RANDOM = 16;
  13. float COUNTER_FINISHCOUNT = 32;
  14. float COUNTER_START_ON = 64;
  15.  
  16. void() counter_on_use;
  17. void() counter_off_use;
  18.  
  19. void() counter_think =
  20.     {
  21.     self.cnt = self.cnt + 1;
  22.     if ( self.spawnflags & COUNTER_RANDOM )
  23.         {
  24.         self.state = random() * self.count;
  25.         self.state = floor( self.state ) + 1;
  26.         }
  27.     else
  28.         {
  29.         self.state = self.cnt;
  30.         }
  31.  
  32.     activator = other;
  33.     SUB_UseTargets();
  34.     self.nextthink = time + self.wait;
  35.  
  36.     if ( self.spawnflags & COUNTER_STEP )
  37.         {
  38.         counter_on_use();
  39.         }
  40.  
  41.     if ( self.cnt >= self.count )
  42.         {
  43.         self.cnt = 0;
  44.         if ( ( self.aflag ) || !( self.spawnflags & COUNTER_LOOP ) )
  45.             {
  46.             if (self.spawnflags & COUNTER_TOGGLE)
  47.                 {
  48.                 counter_on_use();
  49.                 }
  50.             else
  51.                 {
  52.                 remove (self);
  53.                 }
  54.             }
  55.         }
  56.     };
  57.  
  58. void() counter_on_use =
  59.     {
  60.     if ( ( self.cnt != 0 ) && ( self.spawnflags & COUNTER_FINISHCOUNT ) )
  61.         {
  62.         self.aflag = TRUE;
  63.         return;
  64.         }
  65.  
  66.     self.use = counter_off_use;
  67.     self.think = SUB_Null;
  68.     self.aflag = FALSE;
  69.     };
  70.  
  71. void() counter_off_use =
  72.     {
  73.     self.aflag = FALSE;
  74.     if (self.spawnflags & COUNTER_TOGGLE)
  75.         {
  76.         self.use = counter_on_use;
  77.         }
  78.     else
  79.         {
  80.         self.use = SUB_Null;
  81.         }
  82.  
  83.     if ( self.spawnflags & COUNTER_RESET )
  84.         {
  85.         self.cnt = 0;
  86.         self.state = 0;
  87.         }
  88.     self.think = counter_think;
  89.     if (self.delay)
  90.         {
  91.         self.nextthink = time + self.delay;
  92.         }
  93.     else
  94.         {
  95.         counter_think();
  96.         }
  97.     };
  98.  
  99. float( entity counter ) counter_GetCount =
  100.     {
  101.     local float value;
  102.  
  103.     if ( counter.classname == "counter" )
  104.         {
  105.         return counter.state;
  106.         }
  107.     return 0;
  108.     };
  109.  
  110. /*QUAKED func_counter (0 0 0.5) (0 0 0) (32 32 32) TOGGLE LOOP STEP RESET RANDOM FINISHCOUNT START_ON
  111. TOGGLE causes the counter to switch between an on and off state
  112. each time the counter is triggered.
  113.  
  114. LOOP causes the counter to repeat infinitly.  The count resets to zero
  115. after reaching the value in "count".
  116.  
  117. STEP causes the counter to only increment when triggered.  Effectively,
  118. this turns the counter into a relay with counting abilities.
  119.  
  120. RESET causes the counter to reset to 0 when restarted.
  121.  
  122. RANDOM causes the counter to generate random values in the range 1 to "count"
  123. at the specified interval.
  124.  
  125. FINISHCOUNT causes the counter to continue counting until it reaches "count"
  126. before shutting down even after being set to an off state.
  127.  
  128. START_ON causes the counter to be on when the level starts.
  129.  
  130. "count" specifies how many times to repeat the event.  If LOOP is set,
  131. it specifies how high to count before reseting to zero.  Default is 10.
  132.  
  133. "wait"  the length of time between each trigger event. Default is 1 second.
  134.  
  135. "delay" how much time to wait before firing after being switched on.
  136. */
  137.  
  138. void() func_counter =
  139.     {
  140.     if ( !self.wait )
  141.        {
  142.        self.wait = 1;
  143.        }
  144.  
  145.     self.count = floor( self.count );
  146.     if ( self.count <= 0 )
  147.        {
  148.        self.count = 10;
  149.        }
  150.     self.cnt = 0;
  151.     self.state = 0;
  152.  
  153.     self.classname = "counter";
  154.     self.use = counter_off_use;
  155.     self.think = SUB_Null;
  156.    if ( self.spawnflags & COUNTER_START_ON )
  157.       {
  158.       self.think = counter_off_use;
  159.       self.nextthink = time + 0.1;
  160.       }
  161.     };
  162.  
  163. void() oncount_use =
  164.     {
  165.     if ( counter_GetCount( other ) == self.count )
  166.         {
  167.         activator = other;
  168.         SUB_UseTargets();
  169.         }
  170.     };
  171.  
  172. /*QUAKED func_oncount (0 0 0.5) (0 0 0) (16 16 16)
  173. Must be used as the target for func_counter.  When the counter
  174. reaches the value set by count, func_oncount triggers its targets.
  175.  
  176. "count" specifies the value to trigger on.  Default is 1.
  177.  
  178. "delay" how much time to wait before firing after being triggered.
  179. */
  180.  
  181. void() func_oncount =
  182.     {
  183.     self.count = floor( self.count );
  184.     if ( self.count <= 0 )
  185.        {
  186.        self.count = 1;
  187.        }
  188.  
  189.     self.classname = "oncount";
  190.     self.use = oncount_use;
  191.     self.think = SUB_Null;
  192.     };
  193.